import java.util.Locale;

public class Test {
    public static void main(String[] args) {
        System.out.println(isPalindrome("A b.cd  Dcba"));
    }
    public static boolean isLeg(char ch) {
        if((ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) {
            return true;
        }
        return false;
    }
    public static boolean isPalindrome(String s) {
        s = s.toLowerCase();
        int left = 0;
        int right = s.length() - 1;
        while(left < right) {
            while(left < right && !isLeg(s.charAt(left))) {
                left++;
            }
            while(left < right && !isLeg(s.charAt(right))) {
                right--;
            }
            if(s.charAt(left) == s.charAt(right)) {
                left++;
                right--;
            }else {
                return false;
            }
        }
        return true;
    }
}

